<template>
  <div id="detail-nav-bar">
    <nav-bar>
      <div slot="left" class="back" @click="back">
        <img src="~assets/img/common/back.svg" alt="">
      </div>
      <div slot="center" class="box">
        <div v-for="(item,index) in titles"
             :key="item" class="item"
             :class="{active:currentIndex===index}"
             @click="itemClick(index)">{{item}}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
  import NavBar from "components/common/navbar/NavBar";

  export default {
    name: "DetailNavBar",
    components: {NavBar},
    data() {
      return {
        titles: ['商品', '参数', '评论', '推荐'],
        currentIndex: 0
      }
    },
    methods: {
      back() {
        this.$router.back()
      },
      itemClick(index) {
        this.currentIndex = index
        this.$emit('itemClick', index)
      }
    }
  }
</script>

<style scoped>
  .box {
    display: flex;
  }

  .item {
    flex: 1;
    font-size: 14px;
  }

  .active {
    color: var(--color-tint);

  }

  .back {
    margin-top: 7px;
  }
</style>